//
// Created by dgy on 2022/11/8.
//
#include "iostream"
using namespace std;
#include "vector"
#include "queue"
 struct TreeNode {
    int val;
    TreeNode *left;
    TreeNode *right;
    TreeNode(int x) : val(x), left(NULL), right(NULL) {}
};
 /*
  * 层次遍历，考察队列的先进先出
  * */
class Solution {
public:
    vector<int> levelOrder(TreeNode* root) {
        vector<int> vector;
        if (root==NULL)
            return vector;
        queue<TreeNode*> queue;
        queue.push(root);
        while (!queue.empty()){
            if(queue.front()!=NULL){
                TreeNode* p=queue.front();
                vector.push_back(p->val);
                if(p->left!=NULL)
                    queue.push(p->left);
                if (p->right!=NULL)
                    queue.push(p->right);
                queue.pop();
            }
        }
        return vector;
    }
};